﻿<!-- Views/Admin/Questions.cshtml -->
@model List<WebApplication1.Models.Question>

@{
    ViewBag.Title = WebApplication1.Utilities.LanguageManager.GetText("QuestionManagement");
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="container">
    <h2>@WebApplication1.Utilities.LanguageManager.GetText("QuestionManagement") - @ViewBag.ExamName</h2>

    <!-- 显示导入结果消息 -->
    @if (TempData["SuccessMessage"] != null)
    {
        <div class="alert alert-success alert-dismissible" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
            @Html.Raw(TempData["SuccessMessage"])
        </div>
    }

    @if (TempData["WarningMessage"] != null)
    {
        <div class="alert alert-warning alert-dismissible" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
            @Html.Raw(TempData["WarningMessage"])
        </div>
    }

    @if (TempData["ErrorMessage"] != null)
    {
        <div class="alert alert-danger alert-dismissible" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
            @Html.Raw(TempData["ErrorMessage"])
        </div>
    }

    <p>
        <a href="@Url.Action("CreateQuestion", "Admin", new { examId = ViewBag.ExamId })" class="btn btn-primary">
            <i class="glyphicon glyphicon-plus"></i> @WebApplication1.Utilities.LanguageManager.GetText("AddQuestion")
        </a>
        <a href="@Url.Action("ImportQuestions", "Admin", new { examId = ViewBag.ExamId })" class="btn btn-success">
            <i class="glyphicon glyphicon-import"></i> @WebApplication1.Utilities.LanguageManager.GetText("ImportQuestions")
        </a>
        <a href="@Url.Action("Exams", "Admin")" class="btn btn-danger">
            <i class="glyphicon glyphicon-arrow-left"></i> @WebApplication1.Utilities.LanguageManager.GetText("ReturnToExamList")
        </a>
    </p>

    @if (Model.Count == 0)
    {
        <div class="alert alert-info">
            <p>@WebApplication1.Utilities.LanguageManager.GetText("NoQuestions")</p>
        </div>
    }
    else
    {
        <div class="table-responsive">
            <table class="table table-striped table-bordered">
                <thead>
                    <tr>
                        <th width="5%">@WebApplication1.Utilities.LanguageManager.GetText("Number")</th>
                        <th>@WebApplication1.Utilities.LanguageManager.GetText("QuestionContent")</th>
                        <th width="10%">@WebApplication1.Utilities.LanguageManager.GetText("Type")</th>
                        <th width="8%">@WebApplication1.Utilities.LanguageManager.GetText("Score")</th>
                        <th width="15%">@WebApplication1.Utilities.LanguageManager.GetText("CorrectAnswer")</th>
                        <th width="20%">@WebApplication1.Utilities.LanguageManager.GetText("Action")</th>
                    </tr>
                </thead>
                <tbody>
                    @for (int i = 0; i < Model.Count; i++)
                    {
                        var question = Model[i];
                        <tr>
                            <td>@(i + 1)</td>
                            <td>@question.QuestionText</td>
                            <td>
                                @if (question.QuestionType == "Single")
                                {
                                    <span class="label label-primary">@WebApplication1.Utilities.LanguageManager.GetText("SingleChoice")</span>
                                }
                                else if (question.QuestionType == "Multiple")
                                {
                                    <span class="label label-success">@WebApplication1.Utilities.LanguageManager.GetText("MultipleChoice")</span>
                                }
                                else if (question.QuestionType == "TrueFalse")
                                {
                                    <span class="label label-info">@WebApplication1.Utilities.LanguageManager.GetText("TrueFalse")</span>
                                }
                                else if (question.QuestionType == "Fill")
                                {
                                    <span class="label label-warning">@WebApplication1.Utilities.LanguageManager.GetText("FillBlank")</span>
                                }
                            </td>
                            <td>@question.Score</td>
                            <td>@question.CorrectAnswer</td>
                            <td>
                                <div class="btn-group btn-group-sm" role="group">
                                    <a href="@Url.Action("Options", "Admin", new { questionId = question.QuestionId })"
                                       class="btn btn-info" title="@WebApplication1.Utilities.LanguageManager.GetText("OptionManagement")">
                                        <i class="glyphicon glyphicon-list"></i> @WebApplication1.Utilities.LanguageManager.GetText("Options")
                                    </a>
                                    <a href="@Url.Action("EditQuestion", "Admin", new { id = question.QuestionId })"
                                       class="btn btn-warning" title="@WebApplication1.Utilities.LanguageManager.GetText("Edit")">
                                        <i class="glyphicon glyphicon-edit"></i> @WebApplication1.Utilities.LanguageManager.GetText("Edit")
                                    </a>
                                    <a href="@Url.Action("DeleteQuestion", "Admin", new { id = question.QuestionId })"
                                       class="btn btn-danger" title="@WebApplication1.Utilities.LanguageManager.GetText("Delete")">
                                        <i class="glyphicon glyphicon-trash"></i> @WebApplication1.Utilities.LanguageManager.GetText("Delete")
                                    </a>
                                </div>
                            </td>
                        </tr>
                    }
                </tbody>
            </table>
        </div>
    }
</div>

@section Scripts {
    <script>
        $(document).ready(function() {
            // 删除确认
            $('a[href*="DeleteQuestion"]').click(function(e) {
                if (!confirm('@WebApplication1.Utilities.LanguageManager.GetText("ConfirmDeleteQuestion")')) {
                    e.preventDefault();
                }
            });

            // 自动隐藏成功提示（5秒后）
            setTimeout(function() {
                $('.alert-success').fadeOut('slow');
            }, 5000);
        });
    </script>
}